<?php

Validate::Create();

class Validate
{
	private static $validate_instance;
	
	private function __construct()
	{
	
	}
	
	public static function create()
	{
		if(!isset(self::$validate_instance))
		{
			$class = __CLASS__;
			self::$validate_instance = new $class;
		}
		
		return self::$validate_instance;
	}
	
	public static function sql_validate($string)
	{
		if(is_array($string))
		{
			$string = serialize($string);
		}
		
		$string = mysql_real_escape_string($string);
		
		if(is_array($string))
		{
			$string = unserialize($string);
		}

		return $string;
	}
	
	public static function email_validate($string)
	{
		$string = filter_var($string, FILTER_VALIDATE_EMAIL);
		
		return $string;
	}
	
	public static function path_validate()
	{
		$num_args = (func_num_args() - 1);
		$arg = func_get_args();
		$replace = array('\/', '/', '..', '\0');
		$new_args = array();
		$i = 0;
		while($i < $num_args)
		{
			$i++;
			$arg[$i] = str_replace($replace, '', $arg[$i]);
			array_push($new_args, $arg[$i]);
		}
		
		$string = vsprintf($arg[0], $new_args); //replace the safe variables back into the original string
	
		return $string;
	}
}
?>